package com.foodchain.controller;

import com.foodchain.entity.News;
import com.foodchain.service.NewsService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @ClassName 新闻
 * @Description TODO
 * @Author duyuanyuan
 * @Date 2019/3/22 10:16
 * @Version 1.0
 **/
@Controller
@RequestMapping("/news")
public class NewsController extends BaseController{

    @Resource
    private NewsService newsService;

    /*
     * 功能描述:查询新闻列表
     * @param:  * @param page
     * @param size
     * @return: java.lang.String
     * @auther: duyuanyuan
     * @date: 2019/3/27 17:27
     */
    @RequestMapping("/list")
    @ResponseBody
    public String list(@RequestParam(value = "page", defaultValue = "0") Integer page,
                       @RequestParam(value = "size", defaultValue = "0") Integer size){
        Page<News>  data = newsService.list(page,size);
        return JsonCode(0,"success",data);
    }
    /*
     * 功能描述:根据新闻id查询新闻内容
     * @param:  * @param newsId
     * @return: java.lang.String
     * @auther: duyuanyuan
     * @date: 2019/3/27 17:27
     */
    @RequestMapping("/queryNewsContent")
    @ResponseBody
    public String queryNewsContent(String newsId){
        News news = newsService.queryNewsContent(newsId);
        return JsonCode(0,"success",news);
    }
}
